package com.xjcs.saplingplan.const

import android.content.Context
import android.graphics.Color
import android.graphics.drawable.Drawable
import android.graphics.drawable.LayerDrawable
import androidx.core.content.ContextCompat
import com.xjcs.saplingplan.R
import com.xjcs.saplingplan.view.TextDrawable

enum class AppMainTab(val desc: String) {
    INVENTORY("计划"), VIEW("视图"), FOCUS("专注"), COUNTDOWN("倒数日"), STATISTICS("统计"), MEMO("备忘录"), MINE("我的")
}

fun getMainAppDefaultTab(): List<AppMainTab> {
    return mutableListOf<AppMainTab>().apply {
        add(AppMainTab.INVENTORY)
        add(AppMainTab.VIEW)
        add(AppMainTab.FOCUS)
        add(AppMainTab.COUNTDOWN)
        add(AppMainTab.MINE)
    }
}

fun getMainTabIcon(tab: AppMainTab): Int {
    return when (tab) {
        AppMainTab.INVENTORY -> {
            R.drawable.icon_tab_plan
        }

        AppMainTab.VIEW -> {
            R.drawable.icon_tab_view
        }

        AppMainTab.FOCUS -> {
            R.drawable.icon_tab_focus
        }

        AppMainTab.COUNTDOWN -> {
            R.drawable.icon_tab_countdown
        }

        AppMainTab.MEMO -> {
            R.drawable.icon_tab_memo
        }

        AppMainTab.STATISTICS -> {
            R.drawable.icon_tab_statistics
        }

        AppMainTab.MINE -> {
            R.drawable.icon_tab_mine
        }
    }
}

fun createIconWithNumber(context: Context, iconResId: Int, number: Int): Drawable {
    // 获取原始图标
    val icon = ContextCompat.getDrawable(context, iconResId)!!

    // 创建文本Drawable
    val textDrawable = TextDrawable().apply {
        text = number.toString()
        textSize = 10f // 数字大小
        textColor = Color.BLACK // 数字颜色
        setBounds(0, 0, icon.intrinsicWidth, icon.intrinsicHeight)
    }

    // 创建图层Drawable
    val layers = arrayOf(icon, textDrawable)
    return LayerDrawable(layers).apply {
        // 设置数字位置（右上角）
        setLayerInset(
            1,
            icon.intrinsicWidth - 20, // 右偏移
            5, // 上偏移
            0,
            0
        )
    }
}